import { Room } from '../../models/Room'

export class LiveService {
  // 创建直播间
  async createRoom(userId: string, roomData: any) {
    const room = new Room({
      owner: userId,
      title: roomData.title,
      cover: roomData.cover,
      status: 'inactive',
    })

    return await room.save()
  }

  // 开始直播
  async startLive(roomId: string) {
    const room = await Room.findById(roomId)
    if (!room) throw new Error('Room not found')

    room.status = 'live'
    room.startTime = new Date()
    return await room.save()
  }

  // 结束直播
  async endLive(roomId: string) {
    const room = await Room.findById(roomId)
    if (!room) throw new Error('Room not found')

    room.status = 'ended'
    room.endTime = new Date()
    return await room.save()
  }
}
